//
//  CHViewController.m
//  Conversation
//
//  Created by CHAOO on 09/23/2015.
//  Copyright (c) 2015 CHAOO. All rights reserved.
//

#import "CHViewController.h"
#import "JSQConversationViewController.h"
#import "JSQKeyboardViewController.h"

@interface CHViewController() <JSQConversationViewControllerDelegate>

@end

@implementation CHViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    
    switch (indexPath.row) {
        case 0: {
            cell.textLabel.text = @"PUSH";
        }
            break;
        case 1: {
            cell.textLabel.text = @"PRESENT";
        }
            break;
        case 2: {
            cell.textLabel.text = @"键盘";
        }
            break;
        case 3: {
            cell.textLabel.text = @"Single";
        }
            break;
        default:
            break;
    }
    
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0: {
            JSQConversationViewController *vc = [JSQConversationViewController messagesViewController];
            
            vc.senderId = kJSQMeID;
            vc.sessionId = @"456";
            vc.sessionName = @"789";
            vc.senderDisplayName = kJSQMe;
            
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1: {
            JSQConversationViewController *vc = [JSQConversationViewController messagesViewController];
            vc.delegateModal = self;
            vc.senderId = kJSQMeID;
            vc.sessionId = @"456";
            vc.sessionName = @"789";
            vc.senderDisplayName = kJSQMe;
            
            UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:vc];
            
            [self presentViewController:na animated:YES completion:nil];
        }
            break;
        case 2: {
            JSQKeyboardViewController *keyboardViewController = [[JSQKeyboardViewController alloc] init];
            [self.navigationController pushViewController:keyboardViewController animated:YES];
        }
            break;
        case 3: {
            JSQConversationViewController *vc = [CHViewController share];
            
            vc.senderId = kJSQMeID;
            vc.sessionId = @"456";
            vc.sessionName = @"789";
            vc.senderDisplayName = kJSQMe;
            
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}

+ (JSQConversationViewController *)share
{
    static JSQConversationViewController *_JSQConversationViewController;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        _JSQConversationViewController = [JSQConversationViewController messagesViewController];
    });
    return _JSQConversationViewController;
}


- (void)didDismissJSQDemoViewController:(JSQConversationViewController *)vc
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
